package com.devshephard.juchm.interrupt;

import java.util.concurrent.TimeUnit;

public class InterruptTest {

    public static void main(String[] args) throws InterruptedException {

        Thread t1 = new Thread(()->{
            while (true){
                if(Thread.interrupted()){
                    System.out.println("线程被打断");
                    break;
                }
            }
        });

        TimeUnit.SECONDS.sleep(3);

        t1.interrupt(); //打断线程
        t1.isInterrupted();//是否被打断,不会清除打断标记
        t1.interrupted();//是否被打断,会清除打断标记
        t1.join();

    }

}
